<cfcomponent extends="Model" output="false">

	<cffunction name="init">
		
		<cfset beforeUpdate("validateScores")>
		<cfset validatesNumericalityOf(properties="homePlayerGames,awayPlayerGames",when="onUpdate",onlyInteger=true,lessThanOrEqualTo=6,unless="this.homePlayerGames EQ 0 AND this.awayPlayerGames EQ 0")>
	</cffunction>
	
	<cffunction name="validateScores" hint="Make sure there isn't two winners">
		<cfif this.homePlayerGames EQ 6 AND this.awayPlayerGames EQ 6>
			<cfset this.addErrorToBase(message="Cannot have two winners, please re-submit scores")>
			<cfreturn false>
		<cfelseif (this.homePlayerGames LT 6 AND this.homePlayerGames NEQ 0) AND (this.awayPlayergames LT 6 AND this.awayPlayerGames NEQ 0)>
			<cfset this.addErrorTobase(message="Unable to save, no winner has been determined, please re-submit scores")>		
			<cfreturn false>
		<cfelse>
			<cfreturn true>
		</cfif>

	</cffunction>

</cfcomponent>
